package com.sjsoft.video;

import java.util.ArrayList;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

import com.sjsoft.Utils.networkUtility;
import com.sjsoft.chat.video.ListVideo;
import com.sjsoft.chat.video.PayMoney;
import com.sjsoft.chat.video.mainTab;
import com.sjsoft.payment.PayCard;
import com.sjsoft.payment.PaySms;
import com.sjsoft.webservice.UtilsJson;

public class loadPaymentInfor extends AsyncTask<Void, Void, Void>{
	int resultRequest;	
	boolean isNetWork = true;
	private String Imei="";
	private String paytype="";
	private String sCodeCard="";
	private String sSerialCard="";
	private String sTelco="";
	private String profixName="";
	private String profixCode="";
	
	private String sNote;
	
	Context mContext;
	//Constructor
	private ProgressDialog pDlg = null;
	public loadPaymentInfor(Context context) {
		sNote = "";
		mContext = context;
		isNetWork = networkUtility.getInstance(context)
				.isNetworkAvailable();
	}
	
	public void setImei(String sImei)
	{
		this.Imei = sImei;
	}
	
	public void setTypePayment( String paytype)
	{
		this.paytype = paytype;
	}
	
	public void setCodeCard(String sCodeCard)
	{
		this.sCodeCard = sCodeCard;
	}
	
	public void setSerial(String sSerialCard)
	{
		this.sSerialCard = sSerialCard;
	}
	
	public void setCodeCenter(String sTelco)
	{
		this.sTelco = sTelco;
	}
	
	public void setPreNumber(String profixName)
	{
		this.profixName = profixName;
	}
	
	public void setContentSms(String profixCode)
	{
		this.profixCode = profixCode;
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();	
		showProgressDialog(); 
	}
	
	private void showProgressDialog() {
		pDlg = new ProgressDialog(mContext);
		pDlg.setMessage("Đang gửi đến máy chủ...");
		pDlg.setProgressDrawable(mContext.getWallpaper());
		pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pDlg.setCancelable(false);
		pDlg.show();
	}

	@Override
	protected Void doInBackground(Void... params) {
		if (isNetWork) {
			sNote = UtilsJson.payment(Imei, paytype, sCodeCard, sSerialCard, sTelco,  profixName,  profixCode);
			if(paytype.equalsIgnoreCase("0"))
			{
				PaySms paySMS = (PaySms)mContext;
				if(paySMS != null)
				{
					paySMS.showResult(sNote);
				}
			}
			else
			{
				PayCard payCard = (PayCard)mContext;
				if(payCard != null)
				{
					payCard.showResult(sNote);
				}
			}
		} else {
		}
		return null;
	}

	@Override
	protected void onPostExecute(Void result) {
		super.onPostExecute(result);	
		if(pDlg != null)
			pDlg.dismiss();
	}
}

